﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;

using System.Windows.Forms;

namespace PADWH35
{
    public partial class Form6 : Form
    {
        public Form6()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string sql = @"  SELECT    Key1 盘点日期 ,
            Key3 扫描时间,
            Character01 物料编码 ,
            Character03 批次 ,
            Character02 数量,
            Character09 相同包装数,
            Character10 单位数,             
            Character04 仓库 ,
            Character05 库位,
            Character06 仓库ID, 
            Character07 库位ID,           
            CASE CheckBox01 WHEN 0 THEN N'否' ELSE N'是' END 是否已导入,
            SysRowID
  FROM      Ice.UD22
  WHERE     Key2 = N'inventoryScan'
            AND Company = N'NSZ' and (ShortChar01 BETWEEN '2020-12-21' and '2020-12-23') and CheckBox01 =0 order by CheckBox01,Character01";
            dataGridView1.DataSource = DBHelper.ExecuteDt(sql);

        }

        private void button2_Click(object sender, EventArgs e)
        {

            DataTable dt = (DataTable)dataGridView1.DataSource;

            var query = dt.AsEnumerable()
                    .GroupBy(d => new { partNum = d.Field<string>("物料编码"), betchNum = d.Field<string>("批次"), Warehouse = d.Field<string>("仓库ID"), BinNum = d.Field<string>("库位ID") })
                    .Select(g => new
                    {
                        g.Key.partNum,
                        g.Key.betchNum,
                        num = g.Sum(d =>Convert.ToInt32(d.Field<string>("数量"))),
                        g.Key.Warehouse,
                        g.Key.BinNum
                    }).ToList();
            int a = query.Count;
            int b=0;
            foreach (var row in query)
            {
                MessageBox.Show(row.partNum.ToString() + " " + row.betchNum.ToString() + " " + row.num.ToString() + " " + row.Warehouse.ToString() + " " + row.BinNum.ToString());
                
            }
        }

    }
}
